﻿using System;
using System.Collections.Generic;
using System.Linq;
using Medianamik.Core;
using Medianamik.Core.DAL.Repositories;
using Medianamik.Core.Urls;

namespace Medianamik.DummyWebSite.Data.Repositories
{
    public class UrlRepository : IUrlRepository
    {
        private readonly IMedianamikRepository<BaseWebType> _baseWebTypeRepository;

        public UrlRepository(IMedianamikRepository<BaseWebType> baseWebTypeRepository)
        {
            _baseWebTypeRepository = baseWebTypeRepository;
        }

        public IMedianamikRepository<BaseWebType> BaseWebTypeRepository
        {
            get { return _baseWebTypeRepository; }
        }

        public List<UrlXmlDoc> GetUrlXmlDocs()
        {
            return _baseWebTypeRepository.AlllInstancesWithFilters(ContentState.All,
                ActiveStatus.Activated, null, null, null, null, null, null, true).Select(record =>
               new UrlXmlDoc(record.NodeId, record.TypeId, record.ParentNodeId,
                             record.Path,
                             record.CreatedOn, record.Position, record.Depth,
                             false, record.Culture, record.Revision,
                             record.Generation,
                             record.Url)).ToList();
        }

        public List<UrlXmlDoc> GetUrlXmlDocs(Guid pNodeId)
        {
            return _baseWebTypeRepository.AllInstances(pNodeId, ContentState.All, ActiveStatus.Activated).Select(record =>
               new UrlXmlDoc(record.NodeId, record.TypeId, record.ParentNodeId,
                             record.Path,
                             record.CreatedOn, record.Position, record.Depth,
                             false, record.Culture, record.Revision,
                             record.Generation,
                             record.Url)).ToList();
        }
    }
}
